package com.gx.mvp.base;

import android.content.Context;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by Guoxin on 2019/12/05.
 */
public abstract class BasePresenter<V extends BaseView> {

    private CompositeDisposable compositeDisposable = new CompositeDisposable();

    /**
     * 上下文
     */
    protected Context mContext;

    /**
     * 绑定的view
     */
    protected V mView;

    /**
     * 构造方法
     *
     * @param context
     * @param view
     */
    public BasePresenter(Context context, V view) {
        this.mContext = context;
        this.mView = view;
    }

    public void unRegisterDisposable(){
        compositeDisposable.dispose();
    }

    public void registerDisposable(Disposable d){
        compositeDisposable.add(d);
    }

    /**
     * 销毁
     */
    public void onDestroy() {
        unRegisterDisposable();
        if (this.mView != null) {
            this.mView = null;
        }
    }

    /**
     * 判断是否销毁
     *
     * @return
     */
    public boolean isDestroyed() {
        return this.mView == null;
    }

}
